{extend name="layout/base"}

{block name="content"}
<div>   
    <table id="demo" lay-filter="test"></table>
</div>

<script type="text/html" id="status">
    {{# switch(d.status) {
    case -1: }}
    <input type="checkbox" name="status" lay-skin="switch"  lay-text="开启|停用"  value= {{ d.memid}}  lay-filter="status" >
    {{# break;
    case 2: }}
    <input type="checkbox" name="status" lay-skin="switch" checked lay-text="开启|停用"  value= {{ d.memid}}  lay-filter="status" >
    {{# break;
    default: }}
    <span class="layui-btn layui-btn-danger layui-btn-xs">已注册</span>
    {{# break;
    } }}
</script>

<script>
layui.use(['jquery', 'table','form'], function () {
    var $ = layui.jquery,
        table = layui.table,
        form = layui.form;
    table.render({
        elem: '#demo',
        url: 'lists',
        page: true, 
        cols: [[ 
        {field: 'memid', title: 'ID'},
        {field: 'name', title: '会员名'},
        {field: 'mobile', title: '手机'},
         {field: 'card_no', title: '会员卡号',templet:function (d) {
                 if(d.card_no==null||d.card_no=="") return '暂无'
                 return d.card_no;
             }},
        {field: 'retime', title: '注册时间',templet : "<div>{{layui.util.toDateString(d.retime*1000, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
        {field: 'status', title: '状态',templet:'#status'}
        
        ]]
    });
    
    form.on('switch(status)', function(data){
        $.ajax({
            url:'setStatus',
            type:'post',
            data:{
                memid:data.value
            },
            success:function(res){
                if(res.code==0){
                    layer.msg('成功')
                }
            }
        })
    });  
}) 
</script>
{/block}